package com.rz.admin.dubbo.service;

import com.rz.admin.service.IConsumerService;
import consumer.ConsumerInfoService;
import consumer.model.Consumer;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.BeanUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service(version = "1.0.0")
public class ConsumerDubboServiceImpl implements ConsumerInfoService {

    @Resource private IConsumerService consumerService;

    @Override
    public Consumer getById(Integer adminId) {
        com.rz.admin.entity.Consumer admin = consumerService.getById(adminId);
        Consumer newAdmin = new Consumer();
        BeanUtils.copyProperties(admin, newAdmin);
        return newAdmin;
    }

    @Override
    public List<Consumer> getByIds(List<Integer> adminIds) {
        List<com.rz.admin.entity.Consumer> admins = new ArrayList<>(consumerService.listByIds(adminIds));
        List<Consumer> adminList = new ArrayList<>();
        admins.forEach(item->{
            Consumer admin = new Consumer();
            BeanUtils.copyProperties(item,admin);
            adminList.add(admin);
        });
        return adminList;
    }

    /**
     * 获取指定用户的子孙级用户列表（不包含自身）
     * @param id
     * @return
     */
    public List<Consumer> getChildren(Integer id){
        List<com.rz.admin.entity.Consumer> admins = new ArrayList<>();
        this.consumerService.getChildren(id,admins);
        List<Consumer> adminList = new ArrayList<>();
        admins.forEach(item->{
            Consumer admin = new Consumer();
            BeanUtils.copyProperties(item, admin);
            adminList.add(admin);
        });
        return adminList;
    }

    /**
     * 获取指定客户的子孙级客户id列表（不包含自身id）
     * @param id
     * @return
     */
    public List<Integer> getChildrenIds(Integer id){
        return this.consumerService.listChildrenIds(id);
    }

}
